import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { getWeekMonthQuarterYear } from '/@/utils';
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '图标',
    align: "center",
    dataIndex: 'imageUrl',
    customRender: render.renderImage,
  },
  {
    title: '名称',
    align: "center",
    dataIndex: 'title'
  },
  {
    title: '首页地址',
    align: "center",
    dataIndex: 'homeUrl'
  },
  {
    title: '执行前代码',
    align: "center",
    dataIndex: 'homeCodeBefore'
  },
  {
    title: '执行后代码',
    align: "center",
    dataIndex: 'homeCodeAfter'
  },
  {
    title: '接单',
    align: "center",
    dataIndex: 'taskUrl'
  },
  {
    title: '执行前代码',
    align: "center",
    dataIndex: 'taskCodeBefore'
  },
  {
    title: '执行后代码',
    align: "center",
    dataIndex: 'taskCodeAfter'
  },
  {
    title: '登录',
    align: "center",
    dataIndex: 'loginUrl'
  },
  {
    title: '执行前代码',
    align: "center",
    dataIndex: 'loginCodeBefore'
  },
  {
    title: '执行后代码',
    align: "center",
    dataIndex: 'loginCodeAfter'
  },
  {
    title: '获取数据',
    align: "center",
    dataIndex: 'dataUrl'
  },
  {
    title: '执行前代码',
    align: "center",
    dataIndex: 'dataBefore'
  },
  {
    title: '执行后代码',
    align: "center",
    dataIndex: 'dataAfter'
  },
  {
    title: '平台编码',
    align: "center",
    dataIndex: 'code'
  },
  {
    title: '状态',
    align: "center",
    dataIndex: 'state',
    customRender: ({ text }) => {
      return render.renderSwitch(text, [{ text: '是', value: '1' }, { text: '否', value: '0' }])
    },
  },
  {
    title: '令牌类型',
    align: "center",
    dataIndex: 'tokneType_dictText'
  },
  {
    title: '等待(秒)',
    align: "center",
    dataIndex: 'waitTime'
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: "名称",
    field: 'title',
    component: 'Input',
    //colProps: {span: 6},
  },
  {
    label: "接单",
    field: 'taskUrl',
    component: 'Input',
    //colProps: {span: 6},
  },
  {
    label: "登录",
    field: 'loginUrl',
    component: 'Input',
    //colProps: {span: 6},
  },
  {
    label: "获取数据",
    field: 'dataUrl',
    component: 'Input',
    //colProps: {span: 6},
  },
  {
    label: "平台编码",
    field: 'code',
    component: 'Input',
    //colProps: {span: 6},
  },
  {
    label: "令牌类型",
    field: 'tokneType',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: "tokne_type"
    },
    //colProps: {span: 6},
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '图标',
    field: 'imageUrl',
    component: 'Input',
  },
  {
    label: '令牌类型',
    field: 'tokneType',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: "tokne_type"
    },
  },
  {
    label: '名称',
    field: 'title',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入名称!' },
        { ...rules.duplicateCheckRule('cu_platform_management', 'title', model, schema)[0] },
      ];
    },
  },
  {
    label: '首页地址',
    field: 'homeUrl',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入首页地址!' },
        { pattern: /^((ht|f)tps?):\/\/[\w\-]+(\.[\w\-]+)+([\w\-.,@?^=%&:\/~+#]*[\w\-@?^=%&\/~+#])?$/, message: '请输入正确的网址!' },
      ];
    },
  },
  {
    label: '执行前代码',
    field: 'homeCodeBefore',
    component: 'InputTextArea',
  },
  {
    label: '执行后代码',
    field: 'homeCodeAfter',
    component: 'InputTextArea',
  },
  {
    label: '接单',
    field: 'taskUrl',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入接单!' },
        { pattern: /^((ht|f)tps?):\/\/[\w\-]+(\.[\w\-]+)+([\w\-.,@?^=%&:\/~+#]*[\w\-@?^=%&\/~+#])?$/, message: '请输入正确的网址!' },
      ];
    },
  },
  {
    label: '执行前代码',
    field: 'taskCodeBefore',
    component: 'InputTextArea',
  },
  {
    label: '执行后代码',
    field: 'taskCodeAfter',
    component: 'InputTextArea',
  },
  {
    label: '登录',
    field: 'loginUrl',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入登录!' },
        { pattern: /^((ht|f)tps?):\/\/[\w\-]+(\.[\w\-]+)+([\w\-.,@?^=%&:\/~+#]*[\w\-@?^=%&\/~+#])?$/, message: '请输入正确的网址!' },
      ];
    },
  },
  {
    label: '执行前代码',
    field: 'loginCodeBefore',
    component: 'InputTextArea',
  },
  {
    label: '执行后代码',
    field: 'loginCodeAfter',
    component: 'InputTextArea',
  },
  {
    label: '获取数据',
    field: 'dataUrl',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入获取数据!' },
        { pattern: /^((ht|f)tps?):\/\/[\w\-]+(\.[\w\-]+)+([\w\-.,@?^=%&:\/~+#]*[\w\-@?^=%&\/~+#])?$/, message: '请输入正确的网址!' },
      ];
    },
  },
  {
    label: '执行前代码',
    field: 'dataBefore',
    component: 'InputTextArea',
  },
  {
    label: '执行后代码',
    field: 'dataAfter',
    component: 'InputTextArea',
  },
  {
    label: '平台编码',
    field: 'code',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入平台编码!' },
      ];
    },
  },
  {
    label: '状态',
    field: 'state',
    component: 'JSwitch',
    componentProps: {
      options: [1, 0]
    },
  },
  {
    label: '等待(秒)',
    field: 'waitTime',
    component: 'InputNumber',
  },

  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false
  },
];

// 高级查询数据
export const superQuerySchema = {
  imageUrl: { title: '图标', order: 0, view: 'image', type: 'string', },
  title: { title: '名称', order: 1, view: 'text', type: 'string', },
  homeUrl: { title: '首页地址', order: 2, view: 'text', type: 'string', },
  homeCodeBefore: { title: '执行前代码', order: 3, view: 'textarea', type: 'string', },
  homeCodeAfter: { title: '执行后代码', order: 4, view: 'textarea', type: 'string', },
  taskUrl: { title: '接单', order: 5, view: 'text', type: 'string', },
  taskCodeBefore: { title: '执行前代码', order: 6, view: 'textarea', type: 'string', },
  taskCodeAfter: { title: '执行后代码', order: 7, view: 'textarea', type: 'string', },
  loginUrl: { title: '登录', order: 8, view: 'text', type: 'string', },
  loginCodeBefore: { title: '执行前代码', order: 9, view: 'textarea', type: 'string', },
  loginCodeAfter: { title: '执行后代码', order: 10, view: 'textarea', type: 'string', },
  dataUrl: { title: '获取数据', order: 11, view: 'text', type: 'string', },
  dataBefore: { title: '执行前代码', order: 12, view: 'textarea', type: 'string', },
  dataAfter: { title: '执行后代码', order: 13, view: 'textarea', type: 'string', },
  code: { title: '平台编码', order: 14, view: 'text', type: 'string', },
  state: { title: '状态', order: 15, view: 'switch', type: 'string', },
  tokneType: { title: '令牌类型', order: 16, view: 'list', type: 'string', dictCode: 'tokne_type', },
  waitTime: { title: '等待(秒)', order: 17, view: 'number', type: 'number', },
};

/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}